home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / changedir / graphics.c < prev    next >
C/C++ Source or Header  |  1995-11-05  |  3KB  |  145 lines

  1. /*
  2.  * graphics.c
  3.  */
  4.  
  5. /* $Id: graphics.c,v 1.14 1993/07/04 13:22:02 beust Exp $ */
  6.  
  7. struct Library *AmigaGuideBase;        
  8.  
  9. #include <dos/dos.h>
  10. #include <libraries/amigaguide.h>
  11. #include <clib/amigaguide_protos.h>
  12. #include <pragmas/amigaguide_pragmas.h>
  13.  
  14. #include "ccd.h"
  15.  
  16. #define D(x) x
  17.  
  18. #define CCD_AG_PORT "CCDAMIGAGUIDE"
  19.  
  20. struct PrivateVars {
  21.   AMIGAGUIDECONTEXT context;
  22. };
  23.  
  24. static int
  25. initDisplay(struct GlobalVars *gv, struct PrivateVars *vars)
  26. {
  27.   int result = 0;
  28.  
  29.   AmigaGuideBase = OpenLibrary("amigaguide.library", 33);
  30.   if (AmigaGuideBase) {
  31.     struct NewAmigaGuide nag;
  32.  
  33.     memset(& nag, 0, sizeof(nag));
  34.     nag.nag_Name = CCD_FILE_GUIDE;
  35.     nag.nag_Flags = HTF_LOAD_ALL;
  36.     nag.nag_ClientPort = CCD_AG_PORT;
  37.  
  38.     if (! (vars -> context = OpenAmigaGuide(& nag, NULL))) {
  39.       result = IoErr();
  40.       fprintf(stderr, "couldn't open the file, error %d\n", result);
  41.     }
  42.   }
  43.   else {
  44.     fprintf(stderr, "*** couldn't open amigaguide.library\n");
  45.     result = 1;
  46.   }
  47.  
  48.   return result;
  49. }
  50.  
  51. static int
  52. freeDisplay(struct GlobalVars *gv, struct PrivateVars *vars)
  53. {
  54.   int result = 0;
  55.   if (vars -> context) CloseAmigaGuide(vars -> context); vars -> context = NULL;
  56.   if (AmigaGuideBase) CloseLibrary(AmigaGuideBase); AmigaGuideBase = NULL;
  57.  
  58.   return result;
  59. }
  60.  
  61. static int
  62. buildGuideFile(struct GlobalVars *gv, DataBase db)
  63. /* Build a guide file from ccd:.ccdconfig */
  64. {
  65.   FILE *guide;
  66.   int result = 0, i;
  67.   unsigned char *dir;
  68.   Entry entry;
  69.  
  70.   guide = fopen(CCD_FILE_GUIDE, "w");
  71.   if (! guide) {
  72.     fprintf(stderr, "couldn't write to %s\n", CCD_FILE_GUIDE);
  73.     result = 5;
  74.   }
  75.   else {
  76.     unsigned char spaces[128], node[128], line[256];
  77.     int n;
  78.  
  79.     DB_Rewind(db);
  80.  
  81.   /* Create a line corresponding to the directory, with the indentation */
  82.     fprintf(guide, "@database ccd.guide\n\n@node Main\n");
  83.     while (! DB_EndOfDataBase(db)) {
  84.       entry = DB_NextEntry(db);
  85.       fprintf(guide, "%s@{\"%s\" rx \"%s %s\"}\n",
  86.           entry -> spaces, entry -> name, CCD_FILE_REXX, entry -> name);
  87.     }
  88.     fprintf(guide, "\n@endnode\n");
  89.     fclose(guide);
  90.   }
  91.  
  92.   return result;
  93. }
  94.  
  95. static int
  96. buildRexxFile(struct GlobalVars *gv)
  97. /* Build the Rexx file called when the user clicks on a directory */
  98. {
  99.   char *rexxProgram[] = {
  100.     "/**/",
  101.     "",
  102.     "arg dir",
  103.     "ADDRESS CCDAMIGAGUIDE.1 QUIT",
  104.     "if (~ exists('env:ccd')) then",
  105.     "  ADDRESS COMMAND 'Makedir env:ccd'",
  106.     "",
  107.     "ADDRESS COMMAND 'echo ' || dir || ' > ENV:CCD/LAST_DIR'",
  108.     NULL
  109.   };
  110.   int result = 0;
  111.   FILE *f;
  112.  
  113.   f = fopen(CCD_FILE_REXX, "w");
  114.   if (f) {
  115.     char **p = & rexxProgram[0];
  116.     while (*p) {
  117.       fprintf(f, "%s\n", *p);
  118.       p++;
  119.     }
  120.     fclose(f);
  121.   }
  122.   else {
  123.     fprintf(stderr, "*** couldn't create %s\n", CCD_FILE_REXX);
  124.     result = 5;
  125.   }
  126.  
  127.   return result;
  128. }
  129.  
  130.  
  131. void
  132. displayTree(struct GlobalVars *gv, DataBase db)
  133. {
  134.   struct PrivateVars vars;
  135.  
  136.   memset(& vars, 0, sizeof(vars));
  137.   buildGuideFile(gv, db);
  138.   buildRexxFile(gv);
  139.   if (initDisplay(gv, & vars) == 0) {
  140.     freeDisplay(gv, & vars);
  141.   }
  142. }
  143.  
  144.  
  145.